/*
 * Copyright (c) 2019-2029, <a href="https://wwww.intellijboy.cn">https://wwww.intellijboy.cn</a> (liuburu@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * <a href="https://www.apache.org/licenses/LICENSE-2.0">https://www.apache.org/licenses/LICENSE-2.0</a>
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package client.intellijboy.demo;


import client.intellijboy.demo.vo.create.DateTimeReq;
import client.intellijboy.demo.vo.query.DateTimeInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import open.intellijboy.framework.core.exception.BusinessException;
import open.intellijboy.framework.core.response.Result;
import open.intellijboy.framework.core.response.StatusCode;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;


/**
 * @author intellijboy
 * @date 2023/10/3
 * @since 1.0
 */
@Tag(name = "示例验证模块", description = "一些场景自测示例代码演示")
@RestController
@RequestMapping("demo")
public class DemoController {

    @Operation(summary = "报时接口", description = "获取服务端系统时间，时间校对接口")
    @GetMapping("now")
    public Result<DateTimeInfo> now() {
        DateTimeReq dateTimeReq = DateTimeInfo.builder()
                                              .date(new Date())
                                              .localDateTime(LocalDateTime.now())
                                              .localDate(LocalDate.now())
                                              .localTime(LocalTime.now())
                                              .build();
        DateTimeInfo dateTimeInfo = new DateTimeInfo();
        BeanUtils.copyProperties(dateTimeReq, dateTimeInfo);
        return Result.success(dateTimeInfo);
    }

    @Operation(summary = "校时接口", description = "时间校对接口")
    @PutMapping("update/time")
    public DateTimeInfo updateTime(@RequestBody DateTimeReq dateTimeReq) {
        DateTimeInfo dateTimeInfo = new DateTimeInfo();
        BeanUtils.copyProperties(dateTimeReq, dateTimeInfo);
        return dateTimeInfo;
    }

    @Operation(summary = "异常测试", description = "测试服务端异常")
    @GetMapping("testException")
    public Result<DateTimeInfo> testException() {
        throw new BusinessException(StatusCode.SYSTEM_ERROR_B0312);
    }

    @Operation(summary = "响应体测试", description = "测试返回相应体信息")
    @GetMapping("testResponseEntity")
    public Result<String> testResponseEntity() {
        return Result.success("操作成功");
    }

}
